$(function(){
	var active = {
		driver: function(othis) {
			var type = othis.data('type'),
				text = othis.text();

			layer.open({
				type: 1,
				offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
					,
				id: 'layerDemo' + type //防止重复弹出
					,
				content:`<div style="padding: 20px 100px;">
							<form id="choosedriver" class="am-form tpl-form-line-form">
								<div class="am-u-sm-12 cl-p">
									<input type="text" class="tpl-form-input" id="user-name" placeholder="司机名称"/>
								</div>
								<div class="am-u-sm-12 cl-p">
									<ul>
										{foreach $list as $key => $item}
										<li><input type="radio" name="companyname"/><span>{$item}</span></li>
										{/foreach}
									</ul>
								</div>
							</form>
						</div>`,
				btn: ['确定','取消'],
				btnAlign: 'c' //按钮居中
					,
				shade: 0 //不显示遮罩
					,
				yes: function() {
					for(var i=0;i<$('#choosecompany ul li input').length;i++){
						if($('#choosedriver ul li input')[i].checked){
							console.log($('#choosecompany ul li input').next().html())
							$('.drivername')[0].value=$('#choosecompany ul li input').next().html()
							layer.closeAll();
						}else{
							
						}
					}
					
				},
				btn2:function(){
					layer.closeAll();
				}
			});
		},
		company: function(othis) {
			var type = othis.data('type'),
				text = othis.text();

			layer.open({
				type: 1,
				offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
					,
				id: 'layerDemo' + type //防止重复弹出
					,
				content:`<div style="padding: 20px 100px;">
							<form id="choosecompany" class="am-form tpl-form-line-form">
								<div class="am-u-sm-12 cl-p">
									<input type="text" class="tpl-form-input" id="user-name" placeholder="公司名称"/>
								</div>
								<div class="am-u-sm-12 cl-p">
									<ul>
										{foreach $list as $key => $item}
										<li><input type="radio" name="companyname"/><span>{$item}</span></li>
										{/foreach}
									</ul>
								</div>
							</form>
						</div>`,
				btn: ['确定','取消'],
				btnAlign: 'c' //按钮居中
					,
				shade: 0 //不显示遮罩
					,
				yes: function() {
					for(var i=0;i<$('#choosecompany ul li input').length;i++){
						if($('#choosedriver ul li input')[i].checked){
							console.log($('#choosecompany ul li input').next().html())
							$('.drivername')[0].value=$('#choosecompany ul li input').next().html()
							layer.closeAll();
						}else{
							
						}
					}
					
				},
				btn2:function(){
					layer.closeAll();
				}
			});
		}
	}
	$('.drivername').on('click', function() {
		
	 	var othis = $(this), method = othis.data('method');
	    active[method] ? active[method].call(this, othis) : '';
	})
	$('.companyname').on('click', function() {
		
	 	var othis = $(this), method = othis.data('method');
	    active[method] ? active[method].call(this, othis) : '';
	})
})
